package xxl.robotlegs.base 
{
	import flash.utils.Dictionary;
	import xxl.ioc.reflection.IReflector;
	import xxl.robotlegs.core.IContext;
	import xxl.robotlegs.core.ILogger;
	/**
	 * ...
	 * @author XXL
	 */
	public class ExtensionInstaller 
	{
		private const _classes:Dictionary = new Dictionary(true);
		private var _context:IContext;
		private var _logger:ILogger;
		private var _reflector:IReflector;
		
		public function ExtensionInstaller(context:IContext) 
		{
			_context = context;
			_logger = _context.getLogger(this);
			_reflector = _context.injector.reflector;
		}
		
		public function install(extension:Object):void
		{
			if (extension is Class)
			{
				_classes[extension] || install(new extension);
			}
			else
			{
				const extensionClass:Class = _reflector.getClass(extension);
				if (_classes[extensionClass])
				{
					return;
				}
				_logger.debug("安装{0}", [extension]);
				_classes[extensionClass] = true;
				extension.extend(_context);
			}
		}
		
	}

}